package com.budwk.app.waterquality.component;

import com.budwk.app.sys.models.Sys_unit;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysUnitService;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.utils.NutzIocUtils;
import com.budwk.app.waterquality.config.AppException;
import org.apache.commons.lang3.StringUtils;

public class CommonComponent {

    /**
     * 获取当前用户信息
     * @return
     */
    public static Sys_user getCurrentUser() {
        SysUserService userService = NutzIocUtils.getBean(SysUserService.class);
//        Sys_user user = userService.fetch(SecurityUtil.getUserId());
        Sys_user user = userService.fetch("35370b13d27045dab979429e0b3c2120");
        if (user == null) {
            throw new AppException("用户未登陆！");
        }

        SysUnitService unitService = NutzIocUtils.getBean(SysUnitService.class);
        if (StringUtils.isNotEmpty(user.getUnitId())) {
            Sys_unit unit = unitService.fetch(user.getUnitId());
            if (unit != null) {
                user.setUnit(unit);
            }
        }
        return user;
    }
}
